package com.xiguaji.tiktok.v1.tiktok.blogger.repository;

import com.xiguaji.tiktok.v1.tiktok.blogger.model.Blogger;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface BloggerRepository extends CrudRepository<Blogger,Long>, BloggerExtRepository {

    // Blogger findByoUid(Long uid);

    Optional<Blogger> findById(Long id);

    @Query("SELECT * FROM blogger_main where o_uid = :id")
    Optional<Blogger> findByOUid(Long id);

    Optional<Blogger> findByoUniqueId(String uniqueId);

    @Query("SELECT t.*  FROM `blogger_main` t " +
            "INNER JOIN ( SELECT `id` FROM `blogger_main` tt ORDER BY tt.`score` DESC LIMIT :size OFFSET :startPage ) t1 " +
            "ON t.id = t1.id")
    List<Blogger> findByCountSizeOrderByScore(int startPage,int size);
}
